<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
<div class="settings_settel" id="GC_securitity_mobilecode">
    <span>手机验证码：</span>
    <input type="text" class="settings_codeinput" placeholder="请输入短信验证码">
    <a class="settings_telcode" href="javascript:;">获取验证码</a>
    <p class="settings_textpoint" id="GC_SYSTEMSETUP_MOBILE_SUCCESS">短信验证码已发送至<span id="GC_SYSTEMSETUP_MOBILE"></span>
    </p>
    <p class="settings_losepoint" id="GC_SYSTEMSETUP_MOBILE_FAILURE"></p>
    <div><input type="button" class="settings_settel_next" disabled="disabled" value="下一步"></div>
</div>
<script>

    var clickFlag = false;

    <%-- 获取短信验证码 --%>
    function getMobileCode() {
        var reg = new RegExp('cur');
        if (!reg.test($(this).attr("class"))) {
            $.ajax({
                url: '${basePath}v2/sms/sendcurrentuser',
                type: 'POST',
                beforeSend: function () {
                    //关闭所有消息提醒
                    $("#GC_SYSTEMSETUP_MOBILE_SUCCESS").hide();
                    $("#GC_SYSTEMSETUP_MOBILE_FAILURE").hide();
                },
                error: function (response) {
                    $errorMsg(response);
                },
                success: function (ret) {
                    if (ret.result) {
                        var mobilenumber = ret.info;
                        mobilenumber = mobilenumber.substring(0, 3) + "-" + mobilenumber.substring(3, 7) + "-" + mobilenumber.substring(7, mobilenumber.length);
                        $("#GC_SYSTEMSETUP_MOBILE").text("+86 " + mobilenumber);
                        $("#GC_SYSTEMSETUP_MOBILE_SUCCESS").show();
                        clickFlag = true;
                    } else {
                        $("#GC_SYSTEMSETUP_MOBILE_FAILURE").text(ret.info).show();
                    }
                }
            });
        }
    }

    <%-- 验证短信验证码 --%>
    $(".settings_settel_next").click(function () {
        if ($(this).hasClass("cur")) {

            if (!clickFlag) {
                alert("您尚未获取短信验证码");
                return false;
            }
            var mobilecode = $(".settings_codeinput").val();
            if (typeof(mobilecode) != "undefined" && mobilecode.length > 0) {
                $.ajax({
                    url: '${basePath}v2/sms/vaildcode',
                    type: 'GET',
                    data: {"mobileCode": mobilecode},
                    beforeSend: function () {
                        //关闭所有消息提醒
                        $("#GC_SYSTEMSETUP_MOBILE_SUCCESS").hide();
                        $("#GC_SYSTEMSETUP_MOBILE_FAILURE").hide();
                    },
                    error: function (response) {
                        $errorMsg(response);
                    },
                    success: function (ret) {
                        if (ret.result) {
                            $("#GC_securitity_mobilecode").hide();
                            $("#GC_securitity_next").show();
                        } else {
                            $("#GC_SYSTEMSETUP_MOBILE_FAILURE").text(ret.info).show();
                        }
                    }
                });

            }
        }
    });

</script>